//
// Created by Jisam on 2024/6/19.
//
#include <bits/stdc++.h>
using namespace  std;

using i64 = long long;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n ;
    cin >> n;
    vector<int> a(n),b(n),c(n),d(n);
    vector<int> p,q;
    for(int i = 0 ; i < n; i ++){
        cin >> a[i]>> b[i]>> c[i] >> d[i];
        if(c[i] == 0 || d[i] == 1 && a[i] > b[i]){
            q.push_back(i);
        }else{
            p.push_back(i);
        }
    }
    sort(p.begin(),p.end(),
         [&](int i ,int j){
             return a[i]< a[j];
         });
    sort(q.begin(),q.end(),
         [&](int i ,int j){
             return b[i]< b[j];
         });
    cout << p.size() ;
    for (int i = 0; i < p.size(); ++i) {
        cout <<" "<< p[i] + 1 ;
    }
    cout << "\n";
    cout << q.size() ;
    for (int i = 0; i < q.size(); ++i) {
        cout << " "<< q[i] + 1;
    }
    cout << "\n";

    return  0;
}